﻿@model Order
@{
    ViewBag.Title = "Index";
}

<h3 style="color:red;">Quản Lý Đơn Hàng</h3>

<div role="tabpanel">

    <!-- Nav tabs -->
    <ul class="nav nav-tabs" role="tablist">
        <li role="presentation" class="active"><a href="#edit" aria-controls="edit" role="tab" data-toggle="tab">Thêm Đơn Hàng  &nbsp;<span class="glyphicon glyphicon-home"></span>  </a></li>
        <li role="presentation"><a href="#list" aria-controls="list" role="tab" data-toggle="tab">Danh Sách Đơn Hàng  &nbsp;<span class="glyphicon glyphicon-tasks"></span> </a></li>
    </ul>

    <!-- Tab panes -->
    <div class="tab-content">
        <div role="tabpanel" class="tab-pane active" id="edit">
            <h4>@Html.ValidationSummary()</h4>
            @using (Html.BeginForm("Insert", "Order",
    FormMethod.Post, new { enctype = "multipart/form-data" }))
            {
                 
                <div class="row">
                    <div class="col-md-4">

                        <div class="form-group">
                            <div>Id</div>
                            @Html.TextBoxFor(o => o.Id, new { @class = "form-control" })
                        </div>

                        <div class="form-group">
                            <div>Mã Khách Hàng</div>
                            @Html.TextBoxFor(o => o.CustomerId, new { @class = "form-control" })
                        </div>                        

                        <div class="form-group">
                            <div>Địa Chỉ nhận Hàng</div>
                            @Html.TextBoxFor(o => o.Receiver, new { @class = "form-control" })
                        </div>
                        <div class="form-group">
                            <div>Địa Chỉ</div>
                            @Html.TextBoxFor(o => o.Address, new { @class = "form-control" })
                        </div>
                      
                    </div>
                    <div class="col-md-4">
                        <div class="form-group">
                            <div>Ngày Mua</div>
                            @Html.TextBoxFor(o => o.OrderDate, "{0:MM/dd/yyyy}", new { @class = "form-control datepicker" })
                        </div>

                        <div class="form-group">
                            <div>Ngày Giao Hàng</div>
                            @Html.TextBoxFor(o => o.RequireDate, "{0:MM/dd/yyyy}", new { @class = "form-control RequireDate" })
                        </div>
                        <div class="form-group">
                            <div>Tổng Tiền</div>
                            @Html.TextBoxFor(o => o.Amount, new { @class = "form-control" })
                        </div>
                    </div>
                   
                </div>
                 <div class="form-group col-md-12">
                        <div>Ghi Chú</div>
                        @Html.TextAreaFor(o => o.Description, new { rows = 5, @class = "form-control" })
                     <script type="text/javascript">
                         CKEDITOR.replace("Description")
                     </script>

                    </div>
             
                <div class="form-group">
                    <div></div>
                    <div>
                        <button onclick="form.action = '/Admin/Order/Insert'" class="btn btn-default">Insert</button>
                        @if (Model.Id != 0)
                        {
                            <button onclick="form.action = '/Admin/Order/Update'" class="btn btn-default">Update</button>
                                 <a href="/Admin/Order/Delete/@Model.Id" onclick="return Xoa();" class="btn btn-default">Delete</a>
                        }
                        <a href="/Admin/Order/Index" class="btn btn-default">Reset</a>
                    </div>
                </div>
            }
        </div>
        <div role="tabpanel" class="tab-pane" id="list">
            <br/><br/>
            <table class="table table-hover">
                <tr>
                    <th>Id</th>
                    <th>Mã Khách Hàng</th>
                    <th>Ngày Mua </th>
                    <th>Ngày Giao Hàng</th>
                    <th>Địa chỉ nhận</th>
                    <th>Địa Chỉ</th>
                    <th>Ghi Chú</th>
                    <th>Tổng Tiền</th>
                    <th></th>
                </tr>
                @foreach (var s in ViewBag.Orders)
                {
                    <tr>
                        <td>@s.Id</td>
                        <td>@s.CustomerId</td>
                        <td>@s.OrderDate</td>
                        <td>@s.RequireDate</td>
                        <td>@s.Receiver</td>
                        <td>@s.Address</td>                        
                        <td>@s.Description</td>
                        <td>@s.Amount</td>
                        
                        <td>
                            <a href="/Admin/Order/Edit/@s.Id"
                               class="btn btn-default">Edit</a>
                           
                        </td>
                    </tr>
                }
            </table>
        </div>
    </div>

</div>


@section scripts{
<script src="~/jquery-ui/jquery-ui.min.js"></script>
<link href="~/jquery-ui/jquery-ui.min.css" rel="stylesheet" />


<script>
    $(function () {
        $("input.datepicker").datepicker();
        $("input.RequireDate").datepicker();
    });
</script>

<script>
    function Xoa() {
        var ok = confirm("Có chắc chắn xóa mẫu tin có mã  không?");
        if (ok == true) {
            window.location.href = "/Admin/Order/Delete/@Model.Id";
        } else {
            return false;
        }
    }
</script>

}
  